package com.pes.arcww.form;

import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.springframework.security.crypto.bcrypt.BCrypt;

@Entity
@Table(name="USERS")
public class Users{
	
	@Id
	@Column(name = "USU_EMAIL", unique = true, length = 255)
	private String email;
	
	@Column(name = "USU_PASSWORD", length = 255)
	private String password;
	
	@Column(name = "USU_FIRSTNAME", length = 45)
	private String firstName;
	
	@Column(name = "USU_LASTNAME", length = 45)
	private String lastName;
	
	@Column(name = "USU_PRIVILEGES")
	private Integer privileges;
	
	@Column(name = "USU_BADGEID")
	private long badgeID;
	
	@OneToMany(targetEntity= Exams.class, mappedBy = "user")
	@LazyCollection(LazyCollectionOption.FALSE)
	private Collection<Exams> examsList = new ArrayList<Exams>();
	
	
	/**
	 * 
	 * @param email
	 * @param password
	 * @param firstName
	 * @param lastName
	 * @param privileges
	 * @param badgeID
	 */
	public Users(String email, String password, String firstName,
			String lastName, Integer privileges, long badgeID) {
		super();
		this.email = email;
		this.password = BCrypt.hashpw(password, BCrypt.gensalt());
		this.firstName = firstName;
		this.lastName = lastName;
		this.privileges = privileges;
		this.badgeID = badgeID;
	}

	public Users() {
		// TODO Auto-generated constructor stub
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = BCrypt.hashpw(password, BCrypt.gensalt());
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Integer getPrivileges() {
		return privileges;
	}

	public void setPrivileges(Integer privileges) {
		this.privileges = privileges;
	}

	public long getBadgeID() {
		return badgeID;
	}

	public void setBadgeID(long badgeID) {
		this.badgeID = badgeID;
	}
	
	public Collection<Exams> getExamsList() {
		return examsList;
	}

	public void setExamsList(Collection<Exams> examsList) {
		this.examsList = examsList;
	}
	
}
